import Vue from 'vue'
import App from './App.vue'
import router from '@/router/index'
import api from './api/api'
import { getToken} from './utils/auth' // get token from cookie
import {Toast ,Card  ,Uploader , Picker , Button,Tab, Tabs,NavBar,Form,Field  ,Icon ,Search ,Cell, CellGroup,DatetimePicker, Popup    } from 'vant';
import 'vant/lib/index.css';
Vue.use(Toast);
Vue.use(Card);
Vue.use(Button);
Vue.use(Tabs);
Vue.use(Tab);
Vue.use(NavBar);
Vue.use(Form);
Vue.use(Field);
Vue.use(Icon);
Vue.use(Search);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(DatetimePicker);
Vue.use(Popup);
Vue.use(Picker);
Vue.use(Uploader);
Vue.config.productionTip = false
// api
Vue.prototype.$api = api

router.beforeEach((to, from, next) => {
  console.log(to.matched.some(record => record.meta.requireAuth))
  if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
    const hasToken = getToken()
    if (!hasToken) {
      next({
        name: 'login'
      })
    } else {
      next()
    }
  } else {
    next()  
  }
})
new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
